jQuery(document).ready(function(){
		
	/*
	 * Logout
	 * */
	jQuery('a.user-login').click(login);
	
	/*
	 * Login box
	 * */
	jQuery('a.user-logout').click(logout);
	
});

function login(){
	var email = jQuery('input.input-login|[name="user"]').val();
	var pass = jQuery('input.input-login|[name="pass"]').val();

	if (email.length > 3 && pass.length > 3){
		jQuery.ajax({
			type:'POST',
			url:'/ajax/core/users/login.php',
			data:{u: email, p: pass},
			success:function(data){
				var arr = eval(data);
				var urlCurr = jQuery(location).attr('href');
				
				if (arr.result) {
					jQuery(location).attr('href', urlCurr);
				} else {
					jQuery('div.box-login-result').html('Email o Password non corretta');
					jQuery('input.input-login|[name="pass"]').val('');
					alert ("[VOCABULARY|user or password not valid]");
				}
			}
		});
	} else {
		alert ("[VOCABULARY|user or password not valid]");
	}
}

function logout(){
	jQuery.ajax({
		type:'POST',
		url:'/ajax/core/users/logout.php',
		success: function (data){
			var urlCurr = jQuery(location).attr('href');
			jQuery(location).attr('href', urlCurr);
		}
	});
}